package com.brkj.util.view;

import com.brkj.main.R;
import com.brkj.util.PickPhoto.PickPhotoListener;

import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;

public class MyDialog extends Dialog{
	Context context;
	PickPhotoListener pickPhoto;
	public static final int ACTIVITY_PICKLOCAL = 0;
	public static final int ACTIVITY_PICKCAMERA = 1;
	public MyDialog(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		this.context = context;
	}

	public MyDialog(Context context, int theme,PickPhotoListener pickPhotoListener) {
		super(context, theme);
		this.context = context;
		this.pickPhoto=pickPhotoListener;
		setContentView(R.layout.dialog);
        //set window params
        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        Resources resources = context.getResources();
        DisplayMetrics dm = resources.getDisplayMetrics();
        //set width,height by density and gravity
//        params.width = dm.widthPixels;
        params.height = LinearLayout.LayoutParams.WRAP_CONTENT;
        params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
        params.gravity = Gravity.CENTER_HORIZONTAL;
        window.setAttributes(params);
      
        setCanceledOnTouchOutside(true);
        
        SetOnClickListener();

	}

	protected void SetOnClickListener() {
        Button cancel=(Button) findViewById(R.id.cancel);
        Button camerapic=(Button) findViewById(R.id.camerapic);
        Button choosepic=(Button) findViewById(R.id.choosepic);
        cancel.setOnClickListener(new android.view.View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				dismiss();
			}		
		});
        choosepic.setOnClickListener(new View.OnClickListener() {	
			@Override
			public void onClick(View v) {
				pickPhoto.pickphotoListener(ACTIVITY_PICKLOCAL);
				dismiss();
			}
		});
        camerapic.setOnClickListener(new View.OnClickListener() {	
			@Override
			public void onClick(View v) {
				pickPhoto.pickphotoListener(ACTIVITY_PICKCAMERA);
				dismiss();
			}
		});
		
	}
}
